from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-23 14:05:56.834781
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 23, Mar, 2021
Time: 14:06:01
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.0608
Nobs: 239.000 HQIC: -47.8424
Log likelihood: 2818.07 FPE: 9.84943e-22
AIC: -48.3699 Det(Omega_mle): 6.81080e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.446371 0.130076 3.432 0.001
L1.Burgenland 0.071049 0.064281 1.105 0.269
L1.Kärnten -0.216564 0.055666 -3.890 0.000
L1.Niederösterreich 0.088492 0.143813 0.615 0.538
L1.Oberösterreich 0.210754 0.133693 1.576 0.115
L1.Salzburg 0.265092 0.072002 3.682 0.000
L1.Steiermark 0.152248 0.094948 1.603 0.109
L1.Tirol 0.114307 0.063217 1.808 0.071
L1.Vorarlberg -0.038041 0.059086 -0.644 0.520
L1.Wien -0.080279 0.120122 -0.668 0.504
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.477416 0.155276 3.075 0.002
L1.Burgenland 0.008434 0.076735 0.110 0.912
L1.Kärnten 0.340182 0.066450 5.119 0.000
L1.Niederösterreich 0.116308 0.171674 0.677 0.498
L1.Oberösterreich -0.087166 0.159594 -0.546 0.585
L1.Salzburg 0.208587 0.085951 2.427 0.015
L1.Steiermark 0.131585 0.113342 1.161 0.246
L1.Tirol 0.135547 0.075464 1.796 0.072
L1.Vorarlberg 0.161413 0.070533 2.288 0.022
L1.Wien -0.478974 0.143393 -3.340 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.307758 0.062445 4.928 0.000
L1.Burgenland 0.094181 0.030859 3.052 0.002
L1.Kärnten -0.022210 0.026724 -0.831 0.406
L1.Niederösterreich 0.030283 0.069040 0.439 0.661
L1.Oberösterreich 0.303487 0.064182 4.729 0.000
L1.Salzburg 0.013064 0.034566 0.378 0.705
L1.Steiermark 0.012088 0.045581 0.265 0.791
L1.Tirol 0.072380 0.030348 2.385 0.017
L1.Vorarlberg 0.090384 0.028365 3.186 0.001
L1.Wien 0.105259 0.057667 1.825 0.068
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.210461 0.064943 3.241 0.001
L1.Burgenland 0.021291 0.032094 0.663 0.507
L1.Kärnten 0.009739 0.027792 0.350 0.726
L1.Niederösterreich 0.048677 0.071801 0.678 0.498
L1.Oberösterreich 0.397840 0.066749 5.960 0.000
L1.Salzburg 0.081462 0.035948 2.266 0.023
L1.Steiermark 0.142279 0.047404 3.001 0.003
L1.Tirol 0.046562 0.031562 1.475 0.140
L1.Vorarlberg 0.082366 0.029500 2.792 0.005
L1.Wien -0.040522 0.059973 -0.676 0.499
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.517900 0.127013 4.078 0.000
L1.Burgenland 0.081229 0.062767 1.294 0.196
L1.Kärnten 0.007795 0.054355 0.143 0.886
L1.Niederösterreich -0.040397 0.140426 -0.288 0.774
L1.Oberösterreich 0.140893 0.130544 1.079 0.280
L1.Salzburg 0.049601 0.070306 0.705 0.481
L1.Steiermark 0.092811 0.092712 1.001 0.317
L1.Tirol 0.213975 0.061728 3.466 0.001
L1.Vorarlberg 0.039381 0.057695 0.683 0.495
L1.Wien -0.092764 0.117293 -0.791 0.429
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.201442 0.095482 2.110 0.035
L1.Burgenland -0.021328 0.047186 -0.452 0.651
L1.Kärnten -0.028131 0.040862 -0.688 0.491
L1.Niederösterreich -0.054483 0.105566 -0.516 0.606
L1.Oberösterreich 0.443452 0.098137 4.519 0.000
L1.Salzburg 0.005428 0.052853 0.103 0.918
L1.Steiermark -0.011757 0.069696 -0.169 0.866
L1.Tirol 0.167423 0.046404 3.608 0.000
L1.Vorarlberg 0.060111 0.043372 1.386 0.166
L1.Wien 0.244476 0.088175 2.773 0.006
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.245620 0.122826 2.000 0.046
L1.Burgenland 0.020600 0.060698 0.339 0.734
L1.Kärnten -0.060218 0.052564 -1.146 0.252
L1.Niederösterreich -0.054855 0.135797 -0.404 0.686
L1.Oberösterreich 0.007932 0.126242 0.063 0.950
L1.Salzburg 0.075161 0.067989 1.105 0.269
L1.Steiermark 0.345925 0.089656 3.858 0.000
L1.Tirol 0.454640 0.059693 7.616 0.000
L1.Vorarlberg 0.149078 0.055793 2.672 0.008
L1.Wien -0.178707 0.113427 -1.576 0.115
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.123183 0.143639 0.858 0.391
L1.Burgenland 0.047214 0.070984 0.665 0.506
L1.Kärnten -0.064728 0.061470 -1.053 0.292
L1.Niederösterreich 0.209514 0.158808 1.319 0.187
L1.Oberösterreich -0.026853 0.147633 -0.182 0.856
L1.Salzburg 0.213354 0.079510 2.683 0.007
L1.Steiermark 0.134611 0.104848 1.284 0.199
L1.Tirol 0.050859 0.069808 0.729 0.466
L1.Vorarlberg 0.084278 0.065247 1.292 0.196
L1.Wien 0.230258 0.132647 1.736 0.083
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.588765 0.078483 7.502 0.000
L1.Burgenland -0.040431 0.038785 -1.042 0.297
L1.Kärnten -0.025901 0.033587 -0.771 0.441
L1.Niederösterreich 0.010312 0.086771 0.119 0.905
L1.Oberösterreich 0.333358 0.080665 4.133 0.000
L1.Salzburg 0.016534 0.043443 0.381 0.704
L1.Steiermark -0.033338 0.057288 -0.582 0.561
L1.Tirol 0.086846 0.038143 2.277 0.023
L1.Vorarlberg 0.117136 0.035650 3.286 0.001
L1.Wien -0.044494 0.072477 -0.614 0.539
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.136979 0.032895 0.160377 0.217278 0.048814 0.077471 -0.002799 0.158027
Kärnten 0.136979 1.000000 0.009021 0.203718 0.174383 -0.079225 0.158065 0.029758 0.305091
Niederösterreich 0.032895 0.009021 1.000000 0.254646 0.056508 0.267353 0.145152 0.048538 0.308047
Oberösterreich 0.160377 0.203718 0.254646 1.000000 0.301652 0.284531 0.086689 0.059433 0.133492
Salzburg 0.217278 0.174383 0.056508 0.301652 1.000000 0.149177 0.047556 0.099810 -0.004417
Steiermark 0.048814 -0.079225 0.267353 0.284531 0.149177 1.000000 0.117703 0.115591 -0.131744
Tirol 0.077471 0.158065 0.145152 0.086689 0.047556 0.117703 1.000000 0.164433 0.146747
Vorarlberg -0.002799 0.029758 0.048538 0.059433 0.099810 0.115591 0.164433 1.000000 0.005041
Wien 0.158027 0.305091 0.308047 0.133492 -0.004417 -0.131744 0.146747 0.005041 1.000000